﻿<?xml version="1.0"?>
<!-- 
						EonicWeb Rewrite Rules
						Platform:	IIS7 URL Rewrite Module
						Author:		Ali Granger
						Date:		08/06/2009
										  
						This will work out whether to use /default.ashx or /ewcommon/default.ashx
						This accepts both article content link formats (i.e. /itemNNNN and /1234-/item-name)
									  
-->
     <rules>
        <rule name="Ignore Frontpage" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
          <match url="*" />
          <conditions>
            <add input="{USER_AGENT}" pattern="*MSFrontpage*" />
          </conditions>
        </rule>
        <!-- To be amended and un-commented upon GO LIVE -->
         <rule name="Redirect non www" stopProcessing="true" enabled="false">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTP_HOST}" negate="true" pattern="^www\.([.a-zA-Z0-9]+)$" />
          </conditions>
          <action type="Redirect" url="http://www.website.co.uk/{R:0}" />
        </rule>
        <rule name="301 Redirects" enabled="true">
          <match url=".*" />
          <conditions>
            <add input="{301Redirect:{REQUEST_URI}}" pattern="(.+)" />
          </conditions>
          <action type="Redirect" url="{C:1}" appendQueryString="false"  />
        </rule>
        <rule name="EW: Static Rewrites" enabled="true" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{StaticRewrites:{REQUEST_URI}}" pattern="(.+)" />
          </conditions>
          <action type="Rewrite" url="{C:1}" />
        </rule>
        <rule name="EW: Forward root calls to root default.ashx">
          <match url="^(/(\?(.*)?)?)?$" />
          <action type="Rewrite" url="/default.ashx{R:1}" />
        </rule>
        <rule name="EW: Admin Access" enabled="true">
          <match url="^/?admin$" />
          <action type="Redirect" url="/?ewCmd=admin" />
        </rule>
        <rule name="Ignore existing file or directories (check that it's not requesting /default.ashx)" enabled="true" stopProcessing="true">
          <match url="^(?!(/?)default\.ashx)(.*)$" />
          <conditions logicalGrouping="MatchAny">
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" />
            <add input="{REQUEST_FILENAME}" matchType="IsFile" />
          </conditions>
        </rule>
        <rule name="EW: Deal with articles (i.e. /path/NNNNN-/item-name, where NNNNN is the content id)" enabled="true" stopProcessing="false">
          <match url="^(.*?)\/(\d+)-\/" />
          <conditions logicalGrouping="MatchAll" />
          <action type="Rewrite" url="/default.ashx?path=/{R:1}&amp;artid={R:2}" appendQueryString="true" />
        </rule>
        <rule name="EW: Deal with articles at root (i.e. /NNNNN-/item-name, where NNNNN is the content id)" enabled="true" stopProcessing="false">
          <match url="^(\d+)-/" />
          <conditions logicalGrouping="MatchAll" />
          <action type="Rewrite" url="/default.ashx?path=/&amp;artid={R:1}" appendQueryString="true" />
        </rule>
        <rule name="EW: Deal with normal paths" enabled="true">
          <match url="^/?(.+/)*(?!.*\.\w{2,4}([\?\#]|$))([^\?]+?)(\?(.*))?$" />
          <action type="Rewrite" url="/default.ashx?path=/{R:1}{R:3}" appendQueryString="true" />
        </rule>
        <rule name="EW: If root default.ashx does exist, stop processing" enabled="true" stopProcessing="true">
          <match url="^(/?)default\.ashx(.*)$" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" />
          </conditions>
        </rule>
        <rule name="EW: If root default.ashx does NOT exist, forward to ewcommon" enabled="true" stopProcessing="true">
          <match url="^(/?)(default\.ashx)(.*)$" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
          </conditions>
          <action type="Rewrite" url="/ewcommon/{R:2}{R:3}" />
        </rule>
        <!-- Anything  that gets through the rules will illicit a 404 error.-->
      </rules>